package com.feri.sh.api.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.feri.sh.api.service.QuestionService;
import com.feri.sh.common.pojo.bo.QuestionAddBo;
import com.feri.sh.common.pojo.bo.QuestionUpdateBo;
import com.feri.sh.common.pojo.vo.R;
import com.feri.sh.core.entity.Question;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@CrossOrigin
@Api(tags = "发布问题")
public class QuestionController {
    @Resource
    private QuestionService service;

    @GetMapping("/api/question/list")
    @ApiOperation("查询用户发布的问题")
   public R selelctAllQuestion(int uid){
    return  service.queryByUid(uid);
  }

    @ApiOperation("根据问题名称查询")
    @GetMapping("/api/question/querywhere")
    public R where(@RequestParam(required = false,defaultValue = "")String name) {
        QueryWrapper<Question> queryWrapper=new QueryWrapper<>();
        if(!"".equals((name))){
            queryWrapper.like("name",name);
        }

        List<Question> list = service.list(queryWrapper);
        return R.ok(list);
    }
    @PostMapping("/api/question/add")
    @ApiOperation("添加问题")
    public R addQuestion(@RequestBody QuestionAddBo bo){
        return  service.add(bo);
    }

    @GetMapping("/api/question/queryById")
    @ApiOperation("问题回复")
    public R selelctByQid(int id){
        return  service.selectByQid(id);
    }
    @PostMapping("/api/question/updateCount")
    @ApiOperation("更新问题的回答数量")
    public R updateQuestionCount(@RequestBody QuestionUpdateBo bo) {
        return service.updateCount(bo);
    }
}
